﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.Logging;
using ProjTemp.Common.Logging;
using System.ComponentModel.Composition;

namespace ProjTemp.Desktop.Common.Logging
{
    [Export(typeof(ILoggerFacade))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class PrismLoggerAdapter : ILoggerFacade
    {
        private readonly ILogger _logger;
        private const string MessageFormat = "Priority:{0}, Message:{1}";

        [ImportingConstructor]
        public PrismLoggerAdapter(ILogger logger)
        {
            logger.LogType = typeof(PrismLoggerAdapter);
            this._logger = logger;
        }

        public void Log(string message, Category category, Priority priority)
        {
            switch (category)
            {
                case Category.Debug:
                    _logger.DebugFormat(MessageFormat, priority, message);
                    break;
                case Category.Exception:
                    _logger.ErrorFormat(MessageFormat, priority, message);
                    break;
                case Category.Info:
                    _logger.InfoFormat(MessageFormat, priority, message);
                    break;
                case Category.Warn:
                    _logger.WarnFormat(MessageFormat, priority, message);
                    break;
                default:
                    break;
            }
        }
    }
}
